From a4d8a65bc3f47510ef3e6cb4cb451828f220aee7 Mon Sep 17 00:00:00 2001 From: robertl Date: Fri, 28 Aug 2009 17:21:37 +0000 Subject: [PATCH] Remove nonsensical combinations of hardware choices from pull-downs. --- gui/mainwindow.cpp | 59 ++++++++++++++++++++++++++++++++++++++-------- gui/mainwindow.h | 6 ++++- gui/mainwinui.ui | 8 ++++++- 3 files changed, 61 insertions(+), 12 deletions(-) diff --git a/gui/mainwindow.cpp b/gui/mainwindow.cpp index 7971fe6e8..93c723787 100644 --- a/gui/mainwindow.cpp +++ b/gui/mainwindow.cpp @@ -1,5 +1,5 @@ // -*- C++ -*- -// $Id: mainwindow.cpp,v 1.5 2009/08/28 17:08:55 robertl Exp $ +// $Id: mainwindow.cpp,v 1.6 2009/08/28 17:21:37 robertl Exp $ //------------------------------------------------------------------------ // // Copyright (C) 2009 S. Khai Mong . @@ -197,18 +197,41 @@ MainWindow::~MainWindow() if (upgrade) delete upgrade; } + //------------------------------------------------------------------------ -void MainWindow::loadDeviceNameCombos() +void MainWindow::loadInputDeviceNameCombo(QString format) { ui.inputDeviceNameCombo->clear(); + // Later, we can probe the system for multiple USB devices and populate + // here. + if (formatSupportsUSB(format)) + ui.inputDeviceNameCombo->addItem("usb:"); + if (formatSupportsSerial(format)) + osLoadDeviceNameCombos(ui.inputDeviceNameCombo); + // If only one choice, just disable it. + ui.inputDeviceNameCombo->setEnabled(ui.inputDeviceNameCombo->count() > 1); +} + +//------------------------------------------------------------------------ +void MainWindow::loadOutputDeviceNameCombo(QString format) +{ ui.outputDeviceNameCombo->clear(); -#if defined Q_OS_MAC - ui.inputDeviceNameCombo->addItem("usb:"); - ui.outputDeviceNameCombo->addItem("usb:"); + // Later, we can probe the system for multiple USB devices and populate + // here. + if (formatSupportsUSB(format)) + ui.outputDeviceNameCombo->addItem("usb:"); + if (formatSupportsSerial(format)) + osLoadDeviceNameCombos(ui.outputDeviceNameCombo); + // If only one choice, just disable it. + ui.outputDeviceNameCombo->setEnabled(ui.outputDeviceNameCombo->count() > 1); +} - osLoadDeviceNameCombos(ui.inputDeviceNameCombo); - osLoadDeviceNameCombos(ui.outputDeviceNameCombo); -#else +//------------------------------------------------------------------------ +void MainWindow::loadDeviceNameCombos() +{ + loadInputDeviceNameCombo(""); + loadOutputDeviceNameCombo(""); +#if defined Q_OS_MAC for (int i=0; deviceNames[i]; i++) { ui.inputDeviceNameCombo->addItem(deviceNames[i]); ui.outputDeviceNameCombo->addItem(deviceNames[i]); @@ -374,7 +397,7 @@ void MainWindow::browseInputFile() QString str; for (int i=0; isetText(str); @@ -551,6 +574,18 @@ void MainWindow::setComboToFormat(QComboBox *comboBox, const QString &name, bool } } +//------------------------------------------------------------------------ +bool MainWindow::formatSupportsUSB(QString format) +{ + return (format == "garmin" || format == "delbin"); +} + +//------------------------------------------------------------------------ +bool MainWindow::formatSupportsSerial(QString format) +{ + return (format != "delbin"); +} + //------------------------------------------------------------------------ void MainWindow::inputFormatChanged(int comboIdx) { @@ -565,6 +600,8 @@ void MainWindow::inputFormatChanged(int comboIdx) bd.inputFileFormat =formatList[fidx].getName(); else bd.inputDeviceFormat = formatList[fidx].getName(); + + loadInputDeviceNameCombo(formatList[fidx].getName()); } //------------------------------------------------------------------------ @@ -582,6 +619,7 @@ void MainWindow::outputFormatChanged(int comboIdx) else if (ui.outputDeviceOptBtn->isChecked()) bd.outputDeviceFormat = formatList[fidx].getName(); + loadOutputDeviceNameCombo(formatList[fidx].getName()); } //------------------------------------------------------------------------ @@ -931,6 +969,7 @@ void MainWindow::setWidgetValues() ui.inputDeviceOptBtn->setChecked(true); inputDeviceOptBtnClicked(); setComboToFormat(ui.inputFormatCombo, bd.inputDeviceFormat, false); + loadInputDeviceNameCombo(bd.inputDeviceFormat); ui.inputStackedWidget->setCurrentWidget(ui.inputDevicePage); } setComboToDevice(ui.inputDeviceNameCombo, bd.inputDeviceName); @@ -946,6 +985,7 @@ void MainWindow::setWidgetValues() ui.outputDeviceOptBtn->setChecked(true); outputDeviceOptBtnClicked(); setComboToFormat(ui.outputFormatCombo, bd.outputDeviceFormat, false); + loadOutputDeviceNameCombo(bd.outputDeviceFormat); ui.outputStackedWidget->setCurrentWidget(ui.outputDevicePage); } else { @@ -966,7 +1006,6 @@ void MainWindow::setWidgetValues() crossCheckInOutFormats(); displayOptionsText(ui.inputOptionsText, ui.inputFormatCombo, true); displayOptionsText(ui.outputOptionsText, ui.outputFormatCombo, false); - checkCharSetCombos(); updateFilterStatus(); } diff --git a/gui/mainwindow.h b/gui/mainwindow.h index 04974e861..7d5968bdb 100644 --- a/gui/mainwindow.h +++ b/gui/mainwindow.h @@ -1,5 +1,5 @@ // -*- C++ -*- -// $Id: mainwindow.h,v 1.4 2009/08/28 17:08:55 robertl Exp $ +// $Id: mainwindow.h,v 1.5 2009/08/28 17:21:37 robertl Exp $ //------------------------------------------------------------------------ // // Copyright (C) 2009 S. Khai Mong . @@ -68,6 +68,10 @@ private: void setComboToDevice(QComboBox *comboBox, const QString &); void loadDeviceNameCombos(); + void loadInputDeviceNameCombo(QString format); + void loadOutputDeviceNameCombo(QString format); + bool MainWindow::formatSupportsUSB(QString format); + bool MainWindow::formatSupportsSerial(QString format); void loadCharSetCombos(); void checkCharSetCombos(); QString charSetFromCombo(QComboBox *); diff --git a/gui/mainwinui.ui b/gui/mainwinui.ui index aae6063ed..1e9a7ebe5 100644 --- a/gui/mainwinui.ui +++ b/gui/mainwinui.ui @@ -168,6 +168,9 @@ Name of port to which input device is connected + + QComboBox::AdjustToContents + @@ -546,6 +549,9 @@ Name of port to which output device is connected + + QComboBox::AdjustToContents + @@ -618,7 +624,7 @@ 0 0 674 - 26 + 22 -- 2.30.2